import java.util.StringTokenizer;

public class RType
{
	public static void convert(String line, int lineNumber, Assembled assembled)
	{
		StringTokenizer tokenizer = new StringTokenizer(line, " ,\t");
		String value = tokenizer.nextToken();
		int[] temp = new int[3];
		int[] build = new int[8];
		int[] templarge = new int[3];

		templarge = rtable(value);
		temp[0] = Memory.memory(tokenizer.nextToken());
		temp[1] = Memory.memory(tokenizer.nextToken());
		temp[2] = Memory.memory(tokenizer.nextToken());
		
		build[0] = 0;
		build[1] = templarge[0];
		build[2] = temp[1];
		build[3] = temp[2];
		build[4] = temp[0];
		build[5] = templarge[1];
		build[6] = templarge[2];
		build[7] = lineNumber;
		
		assembled.addLine(build);
	}
	public static void moveconvert(String line, int lineNumber, Assembled assembled)
	{
		int[] build = new int[8];
		String temp;
		StringTokenizer tokenizer = new StringTokenizer(line, " ,\t");
		temp = tokenizer.nextToken();
		temp = tokenizer.nextToken();
		
		build[0] = 0;
		build[1] = 0;
		build[2] = Memory.memory(tokenizer.nextToken());
		build[3] = 0;
		build[4] = Memory.memory(temp);
		build[5] = 0;
		build[6] = 32;
		build[7] = lineNumber;
		
		assembled.addLine(build);
	}
/*
//	generates the output that is necessary for an r-type command
	public static String rcommand(String input)
	{
		StringTokenizer tokenizer = new StringTokenizer(input, " ,\t");
		String value = tokenizer.nextToken();
		String[] temp = new String[3];
		String build = new String();
		int[] templarge = new int[3];

		templarge = rtable(value);
		temp[0] = "" + Memory.memory(tokenizer.nextToken());
		temp[1] = "" + Memory.memory(tokenizer.nextToken());
		temp[2] = "" + Memory.memory(tokenizer.nextToken());
		
		build = templarge[0] + " " + temp[1] + " " + temp[2] + " " + temp[0] + " " + templarge[1] + " " + templarge[2];
		
		return build;
	}
*/
	//generates the values that are used for r-type commands
	public static int[] rtable(String command)
	{
		command = command.trim();
		int[] var = new int[3];
		if(command.equals("add"))
		{
			var[0] = 0; // "000000";
			var[1] = 0; //"00000";
			var[2] = 32; //"100000";
			return var;
		}

		if(command.equals("addu"))
		{
			var[0] = 0; // "000000";
			var[1] = 0; //"00000";
			var[2] = 33; //"100001";
			return var;
		}

		if(command.equals("and"))
		{
			var[0] = 0; // "000000";
			var[1] = 0; //"00000";
			var[2] = 36; //"100100";
			return var;
		}

		if(command.equals("or"))
		{
			var[0] = 0; //"000000";
			var[1] = 0; //"00000";
			var[2] = 37; //"100101";
			return var;
		}

		if(command.equals("sub"))
		{
			var[0] = 0; //"000000";
			var[1] = 0; //"00000";
			var[2] = 34; //"100010";
			return var;
		}

		if(command.equals("subu"))
		{
			var[0] = 0; //"000000";
			var[1] = 0; //"00000";
			var[2] = 35; //"100011";
			return var;
		}
	
		if(command.equals("slt"))
		{
			var[0] = 0; //"000000";
			var[1] = 0; //"00000";
			var[2] = 42; //"101010";
			return var;
		}

		if(command.equals("sltu"))
		{
			var[0] = 0; //"000000";
			var[1] = 0; //"00000";
			var[2] = 43; //"101011";
			return var;
		}
		if(command.equals("sllv"))
		{
			var[0] = 0; //"000000";
			var[1] = 0; //"00000";
			var[2] = 4; //"000100";
			return var;
		}
		if(command.equals("srlv"))
		{
			var[0] = 0; //"000000";
			var[1] = 0; //"00000";
			var[2] = 6; //"000110";
			return var;
		}
		if(command.equals("xor"))
		{
			var[0] = 0; //"000000";
			var[1] = 0; //"00000";
			var[2] = 38; //"100110";
			return var;
		}
		return var;
	}
}